package com.lzh.prometheus.config.exceptionnotice;

import com.lzh.prometheus.config.annos.ConditionalOnExceptionNotice;
import com.lzh.prometheus.exceptionhandle.ExceptionHandler;
import com.lzh.prometheus.properties.PromethreusNoticeProperties;
import com.lzh.prometheus.properties.exception.ExceptionNoticeProperties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author zhehen.lu
 * @date 2025/8/15 9:55
 */
@Configuration
@ConditionalOnExceptionNotice
@EnableConfigurationProperties({ ExceptionNoticeProperties.class })
public class ExceptionNoticeConfig {
    private final Log logger = LogFactory.getLog(ExceptionNoticeConfig.class);

    @Bean
    public ExceptionHandler exceptionHandler(PromethreusNoticeProperties noticeProperties,
                                             ExceptionNoticeProperties exceptionNoticeProperties, ApplicationEventPublisher applicationEventPublisher) {
        logger.debug("创建异常处理器");
        ExceptionHandler exceptionHandler = new ExceptionHandler(noticeProperties, exceptionNoticeProperties,
                applicationEventPublisher);
        return exceptionHandler;
    }
}
